package com.atguigu.gmall.seckill.controller;/*
 * @author: XueYouPeng
 * @time: 23.8.2 下午 11:19
 */


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.result.ResultCodeEnum;
import com.atguigu.gmall.seckill.dto.SeckillOrderSubmitDto;
import com.atguigu.gmall.seckill.service.SeckillGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/api/activity/seckill")
public class SeckillController {

    @Autowired
    private SeckillGoodsService seckillGoodsService ;

    @GetMapping(value = "/auth/getSeckillSkuIdStr/{skuId}")
    public Result<String> getSeckillSkuIdStr(@PathVariable(value = "skuId") Long skuId) {
        String seckillCode = seckillGoodsService.getSeckillSkuIdStr(skuId) ;
        return Result.build(seckillCode , ResultCodeEnum.SUCCESS) ;
    }

    @PostMapping(value = "/auth/seckillOrder/{skuId}")
    public Result queue (@PathVariable(value = "skuId") Long skuId ,@RequestParam(value = "skuIdStr") String skuIdStr){
        seckillGoodsService.queue(skuId , skuIdStr);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @GetMapping(value = "/auth/checkOrder/{skuId}")
    public Result checkOrder(@PathVariable(value = "skuId") Long skuId){
        ResultCodeEnum resultCodeEnum = seckillGoodsService.checkOrder(skuId) ;
        return Result.build(null , resultCodeEnum);
    }

    @PostMapping(value = "/auth/submitOrder")
    public Result<String> submitOrder(@RequestBody SeckillOrderSubmitDto seckillOrderSubmitDto){
        String orderId = seckillGoodsService.submitOrder(seckillOrderSubmitDto);
        return Result.build(orderId , ResultCodeEnum.SUCCESS);
    }

}
